<?php
namespace app\index\controller;
use app\index\model\Channel;
use think\Request;
use think\Db;
class Index extends Base
{
    public function index()
    {
        $mark="index";
        // $id=request()->param('id');
        // $p=request()->param('p'); 
        // if(!$p){
        //     $p=1;
        // }

        // $channelModel=new Channel();
        // if($id){
        //     $mark=$channelModel->getMarkByid($id);
        // }else{
        //     $mark="index";
        // }
        // $pid=$channelModel->getFieldById($id,"pid");
        // if($pid > 0){
        //     $gcid=$pid;
        //     $pcid=$id;
        //     $where['cid']=$id;
        //     $lchannel=$channelModel->getLeftChannel($pid);
        //     $fname=$channelModel->getFieldById($pid,"name");
        // }else{
        //     $gcid=$id;
        //     $pcid=$channelModel->getIdByPid($id);
        //     // $pcid=$channel->where("status=1 and pid=".$id)->order("sort asc ,id desc")->value("id");;
        //     $where['cid']=$pcid;
        //     $lchannel=$channelModel->getLeftChannel($id);
        //     $fname=$channelModel->getFieldById($id,"name");
        // }
        // $mess=$this->getData($mark,$where,$p);
        // print_r($mark);exit;
        $where['status']=1;

        $where['cid']=14;
        // $where['is_home']=1; 
        $notice=db("cms_article")->where($where)->order("sort asc ,id desc")->limit(5)->select();
        $gdwhere['thumb']=array("neq",'');
        $gsnews=db("cms_article")->where($gdwhere)->order("sort asc ,id desc")->limit(5)->select();
        for ($i=0; $i < count($gsnews); $i++) { 
            $gsnews[$i]['annexes']=db("filex")->where("id=".$gsnews[$i]['thumb'])->value("thumb");
        }
        $ltwhere['thumb']=array("eq",'');
        // $ltwhere['is_home']=1;
        $listnews=db("cms_article")->where($ltwhere)->order("sort asc ,id desc")->limit(7)->select();
        for ($i=0; $i < count($listnews); $i++) { 
            $listnews[$i]['cname']=db("channel")->where("id=".$listnews[$i]['cid'])->value("name");
        }

        $productId=db("channel")->where("status=1 and pid=2")->column("id");
        $prowhere['cid']=array("in",$productId);
        $prowhere['status']=1;
        // $prowhere['is_home']=1;
        $product=db("cms_product")->where($prowhere)->order("sort asc , id DESC")->limit(8)->select();
        for ($i=0; $i < count($product); $i++) { 
            $product[$i]['cname']=db("channel")->where("id=".$product[$i]['cid'])->value("name");
            $product[$i]['annexes']=db("filex")->where("id=".$product[$i]['thumb'])->value("thumb");
        }
        
        $dealer=db("cms_article")->where("cid=19")->order("sort asc ,id desc")->limit(4)->select();    
        
        $zszc=db("cms_article")->where("cid=5")->order("sort asc ,id desc")->limit(3)->select();
        $this->assign("zszc",$zszc);
        $this->assign("dealer",$dealer);
        $this->assign("ad",$ad);
        $this->assign("product",$product);
        $this->assign("gsnews",$gsnews);
        $this->assign("listnews",$listnews);
        $this->assign("banner",$banner);
        $this->assign("notice",$notice);
		return view($mark);
    }
}
